<?php /*a:2:{s:57:"E:\source\EasyPeak\application\admin\view\auth\index.html";i:1575113079;s:75:"E:\source\EasyPeak\application\admin\view\..\..\common\view\admin_base.html";i:1572404708;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑后台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href=" /test/static/fontawesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/test/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/test/static/admin/admin.css" media="all">
    <script src="/test/static/js/jquery.min.js"></script>
</head>
<body>
<script src="/test/static/layui/layui.js"></script>
<script>
    layui.use(['form'],function(){
        var form = layui.form;
        form.on('submit(reset)',function(){
            location.reload();
        })
    })
</script>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <button class="layui-btn layui-btn-warm">权限列表</button>
            <div class="layui-btn-group layui-form">
                <?php if(key_exists('admin/auth/add',$btns)): ?>
                <a class="layui-btn openfrm" data-href="<?php echo url('admin/auth/add'); ?>"><i class="layui-icon layui-icon-add"></i>增加</a>
                <?php endif; ?>
            </div>
            <table class="layui-table layui-form" id="tree-table" lay-size="sm"></table>
        </div>
    </div>
</div>

<script type="text/html" id="checkboxTpl">
    <input type="checkbox" disabled name="close" lay-skin="switch" lay-text="是|否" {{ d.ismenu == 1 ? 'checked' : '' }} >
</script>

<script type="text/html" id="actionTpl">
    <?php if(key_exists('admin/auth/edit',$btns)): ?>
    <a class="layui-btn  layui-btn-xs openfrm" data-href="<?php echo url('admin/auth/edit'); ?>?id={{d.guid}}"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <?php endif; if(key_exists('admin/auth/remove',$btns)): ?>
    <a class="layui-btn layui-btn-danger layui-btn-xs removebtn" data-href="<?php echo url('admin/auth/remove'); ?>?id={{d.guid}}"><i class="layui-icon layui-icon-delete"></i>删除</a>
    <?php endif; ?>
</script>

<script>
    layui.config({
        base: '/test/static/layui/extend/'
    }).extend({
        treeTable:'treeTable'
    }).use(['treeTable','layer','code','form','element','laytpl'],function(){
            var form = layui.form,
                layer = layui.layer,
                treeTable = layui.treeTable,
                tree = null;
            var laytpl = layui.laytpl;

            $.post("<?php echo url('admin/auth/index'); ?>?type=list",function(res){
                tree = treeTable.render({
                    elem: '#tree-table',
                    data: res.data,
                    icon_key: 'name',
                    primary_key: 'guid',
                    parent_key: 'pid',
                    is_checkbox: true,
                    is_cache: false,
                    checked: {
                        key: 'guid',
                        data: [],
                    },
                    end: function(e){
                        $("#tree-table .layui-icon-triangle-r").removeClass('layui-icon-triangle-r').addClass('layui-icon-triangle-d');
                        $("#tree-table tr.layui-hide").removeClass('layui-hide');
                        form.render();
                        $.bindactions();
                    },
                    cols: [
                        {
                            key: 'name', title: '名称',width: '200px',
                            template:function(item){
                                return '<a style="cursor:pointer;">'+item.name+'</a>';
                            }
                        },
                        {
                            key: 'icon', title: '图标',width: '260px',
                            template:function(item){
                                return '<i class="'+item.icon+'" style="margin-right:5px;"></i>'+item.icon;
                            }
                        },
                        {
                            key: 'action', title: '路径',width: '260px'
                        },
                        {
                            key: 'sort', title: '排序',width: '60px'
                        },
                        {
                            title: '是否菜单', width: '100px', align: 'center',
                            template: function(item){
                                var tmp = "";
                                laytpl($("#checkboxTpl").html()).render(item,function(html){
                                    tmp = html;
                                });
                                return tmp;
                            }
                        },
                        {
                            title: '操作', align: 'left', width:'220px',
                            template: function(item){
                                var tmp = "";
                                laytpl($("#actionTpl").html()).render(item,function(html){
                                    tmp = html;
                                });
                                return tmp;
                            }
                        },
                        {
                            title:'',
                            template:function(item){
                                return '';
                            }
                        }
                    ]
                });
            });

            $.bindactions = function(){
                $(".openfrm").on('click',function(){
                    var href = $(this).data('href');
                    top.layer.open({
                        type: 2
                        ,title:'编辑框'
                        ,content: href
                        ,area: ['750px', '520px']
                    });
                });

                $(".removebtn").on('click',function(){
                    var url = $(this).data('href');
                    top.layer.confirm("确定删除吗？此操作不能撤销！", {icon: 3, title:'提示'},
                        function(index){
                            top.layer.closeAll();
                            $.post(url,function(res){
                                layer.msg(res.msg,{
                                    offset: '15px'
                                    ,icon: 1
                                    ,time: 1000
                                },function(){
                                    document.location.reload();
                                });
                            });
                        },function (index) {
                            top.layer.close(index);
                        }
                    );
                });
            }

        })
</script>

</body>
</html>